import Vue from 'vue'
import store from '../store/index'
import Router from 'vue-router'

Vue.use(Router)



const router = new Router({
  routes: [
    {
      path: '/',
      title: '登录',
      name: 'login',
      component: resolve => require(['@/components/login'], resolve),
    },{
      path: '/phoneHome',
      title: 'NFC标签管理',
      component: resolve => require(['@/components/phone/phonelayout'], resolve),
      children:[
        {
          path: '',
          title: 'NFC标签管理',
          name: 'phoneHome',
          component: resolve => require(['@/components/phone/phoneHome'], resolve),
        },{
          path: '/addTag',
          title: '新增',
          name: 'addTag',
          component: resolve => require(['@/components/phone/addTag'], resolve),
        },{
          path: '/replaceTag',
          title: '新增',
          name: 'replaceTag',
          component: resolve => require(['@/components/phone/replaceTag'], resolve),
        }
      ]
    },{
      path: '/home',
      title: '首页',
      component: resolve => require(['@/components/layout'], resolve),
      children:[
        {
          path: '',
          title: '首页',
          name: 'home_index',
          component: resolve => require(['@/components/home'], resolve),
        },{
          path: '/devstatus_index',
          title: '设备状态',
          name: 'devstatus_index',
          component: resolve => require(['@/components/devstatus/devstatus'], resolve)
        },{
          path: '/historical_index',
          title: '历史温度',
          name: 'historical_index',
          component: resolve => require(['@/components/historical_temperature/historical_temperature'], resolve),
        },{
          path: '/setting_index',
          title: '系统设置',
          name: 'setting_index',
          component: resolve => require(['@/components/setting/setting'], resolve),
        },{
          path: '/warnning_index',
          title: '温度预警',
          name: 'warnning_index',
          component: resolve => require(['@/components/temperature_warning/temperature_warnning'], resolve),
        },{
          path: '/useradmin_index',
          title: '温度告警',
          name: 'useradmin_index',
          component: resolve => require(['@/components/useradmin/useradmin'], resolve),
        },{
          path: '/devstatus_detail',
          title: '运行状态',
          name: 'devstatus_detail',
          component: resolve => require(['@/components/devstatus/devdetails'], resolve),
        },{
          path: '/warning_detail',
          title: '告警详情',
          name: 'warning_detail',
          component: resolve => require(['@/components/temperature_warning/warningdetail'], resolve),
        },{
          path: '/devgroup',
          title: '变电站',
          name: 'devgroup_index',
          component: resolve => require(['@/components/devstatus/devstatus'], resolve),
        },{
          path: '/devgroup_detail',
          title: '编组详情',
          name: 'devgroup_detail',
          component: resolve => require(['@/components/devgroup/devgroup_home'], resolve),
        }
      ]
    },
  ]
})

router.beforeEach((to,form,next)=>{
  if(to.name=='login'){
    next();
  }else if(!store.state.userinfo.Uname){
    //router.replace({name:'login'});
    //return;
    next();
  }else{
    next();
  }
});

export default router;
